﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExpertMIS.Brokers;
using ExpertMIS.Entities;
using System.Collections;
using System.Text;

namespace ExpertMIS.Forums
{
    public partial class PostSuccessed : System.Web.UI.Page
    {
        private void LoadQuestion(string QuestionOID)
        {
            QuestionBroker broker = new QuestionBroker();
            QuestionEntity question = broker.GetQuestionEntityByOID(QuestionOID);

            if (question == null)
            {
                return;
            }

            pTitle.InnerHtml = question.Title;
            pContext.InnerHtml = question.Context;
            pOthers.InnerHtml = "";

            #region 问题领域
            StringBuilder sbDomains = new StringBuilder();
            QuestionDomainBroker qdBroker = new QuestionDomainBroker();
            IList<QuestionDomainEntity> qdList = qdBroker.GetQuestionDomainsByQuestionOID(question.OID);

            Hashtable htKeys = new Hashtable();
            DomainBroker domainBroker = new DomainBroker();
            foreach (QuestionDomainEntity questionDomain in qdList)
            {
                htKeys["OID"] = questionDomain.DomainOID;
                DomainEntity domainEntity = domainBroker.GetEntity(htKeys) as DomainEntity;
                if(domainEntity != null)
                {
                    if (sbDomains.Length > 0) sbDomains.Append("|");
                    sbDomains.Append(string.Format("<a href='#'>{0}</a>", domainEntity.DomainName));
                }
            }
            pDomains.InnerHtml = sbDomains.ToString();
            #endregion

            #region 涉及专家
            StringBuilder sbExperts = new StringBuilder();
            QuestToExpertsBroker qteBroker = new QuestToExpertsBroker();
            IList<QuestToExpertsEntity> qteList = qteBroker.GetQuestToExpertsByQuestionOID(question.OID);

            ExpertBroker expertBroker = new ExpertBroker();
            foreach(QuestToExpertsEntity qteEntity in qteList)
            {
                htKeys["OID"] = qteEntity.ExpertOID;
                ExpertEntity expertEntity = expertBroker.GetEntity(htKeys) as ExpertEntity;
                if (expertEntity != null)
                {
                    if (sbExperts.Length > 0) sbExperts.Append("|");
                    sbExperts.Append(string.Format("<a href='#'>{0}</a>", expertEntity.Name));
                }
            }
            pExperts.InnerHtml = sbExperts.ToString();

            #endregion
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            LoadQuestion(Request["oid"]);
        }
    }
}
